package com.tcoiss.common.component.dataentity;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import com.tcoiss.common.component.api.RemoteApiService;
import com.tcoiss.common.core.utils.SpringUtils;
import org.apache.ibatis.annotations.Param;

import com.alibaba.fastjson.JSON;

public class MyProxyView implements InvocationHandler {

    public static Object newInstance(Class[] interfaces) {
        return Proxy.newProxyInstance(MyProxyView.class.getClassLoader(),
                interfaces, new MyProxyView());
    }


    @Override
    public Object invoke(Object proxy, Method method, Object[] args)
            throws Throwable {
        String methodName = method.getName();
        System.out.println("调用的方法名称为:"+methodName);
        Class<?> returnType = method.getReturnType();
        System.out.println("返回的类型为"+returnType.getName());
        //这里测试下使用json解析数据后返回.
        Object parseObject = JSON.parseObject("{res:\"ff\"}",
                returnType);




        //通过注解去取注解上的value
        Annotation parameterAnnotations[][] = method.getParameterAnnotations();
        for (int i = 0; i < parameterAnnotations.length; i++) {
            for (Annotation annotation : parameterAnnotations[i]) {
                if (Param.class.equals(annotation.annotationType())) {
                    Param o= ((Param) annotation);
                    String value = o.value();
                    System.out.println(value);
                }
            }
        }


        return parseObject;
    }
    public static void main(String[] args)   {
//        RemoteApiService remoteApiService = (RemoteApiService)MyProxyView.newInstance(new Class[]{RemoteApiService.class});
//
//        remoteApiService.executeApi(null);

    }
}
